package com.mingqi.enetconnected.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;

import com.mingqi.enetconnected.R;
import com.ruffian.library.widget.RTextView;

public class CheckTextView extends RTextView implements Checkable {
    private boolean mChecked = false;

    public CheckTextView(Context context) {
        super(context);
    }

    public CheckTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private static final int[] CHECKED_STATE_SET = { R.attr.text_color_pressed};


    @Override
    public void setChecked(boolean b) {

        if (b != mChecked) {
            mChecked = b;
            this.setBackgroundColor(this.getHelper().getBackgroundColorPressed());
            //  refreshDrawableState();
        }else {
            this.setBackgroundColor(this.getHelper().getBackgroundColorNormal());
        }
    }

    @Override
    public boolean isChecked() {
        return mChecked;
    }

    @Override
    public void toggle() {

        setChecked(!mChecked);
    }


    @Override
    protected int[] onCreateDrawableState(int extraSpace) {

        final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);

        if (isChecked()) mergeDrawableStates(drawableState, CHECKED_STATE_SET);

        return drawableState;
    }
}
